//login module
import { makeAutoObservable } from 'mobx'
import {http,setToken,getToken,removeToken} from '@/uitls'
class LoginStore {
    token = getToken() || ''
    constructor() {
        //响应式处理 绑定this
        makeAutoObservable(this)
    }
    getToken = async ({mobile, code}) => {
        //调用登录接口
        const res = await http.post('http://geek.itheima.net/v1_0/authorizations', {
            mobile,
            code
        })

        //存入token
        this.token = res.data.token
        //存入本地存储
        setToken(this.token)
    }
    //退出登录函数
    loginOut = () => {
        this.token = ''
        removeToken()
    }
}
export default LoginStore